package cn.golxen.counter.service.impl;

import cn.golxen.commons.vo.CounterVO;
import cn.golxen.counter.entity.Suspend;
import cn.golxen.counter.feign.GoodsFeign;
import cn.golxen.counter.mapper.SuspendMapper;
import cn.golxen.counter.service.SuspendService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class SuspendServiceImpl implements SuspendService {

    @Autowired SuspendMapper suspendMapper;
    @Autowired
    GoodsFeign goodsFeign;
    @Override
    public Integer addSuspend(List<Suspend> suspend) {
        return suspendMapper.addSuspend(suspend);
    }

    @Override
    public Integer deleteSuspend(List<Suspend> suspend) {
        return suspendMapper.deleteSuspend(suspend);
    }

    @Override
    public Integer sellSuspend(List<Suspend> suspend) {
        List<CounterVO> counterVOS=new LinkedList<>();
        CounterVO counterVO = new CounterVO();
        for (Suspend item :suspend) {
            BeanUtils.copyProperties(item,counterVO);
            counterVOS.add(counterVO);
        }
        if (suspendMapper.deleteSuspend(suspend)!=0){
            goodsFeign.updateGoodsInventory(counterVOS);
            return 1;
        }
        return 0;
    }

    @Override
    public List<Suspend> getSuspend() {
        return suspendMapper.getSuspend();
    }
}
